<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Windows 11 通知示例</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .container {
            text-align: center;
            background: white;
            padding: 40px;
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            max-width: 400px;
        }
        
        h1 {
            color: #333;
            margin-bottom: 30px;
            font-size: 24px;
        }
        
        .notification-btn {
            background: #0078d4;
            color: white;
            border: none;
            padding: 12px 24px;
            font-size: 16px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s ease;
            margin: 10px;
        }
        
        .notification-btn:hover {
            background: #106ebe;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 120, 212, 0.3);
        }
        
        .notification-btn:active {
            transform: translateY(0);
        }
        
        .status {
            margin-top: 20px;
            padding: 10px;
            border-radius: 6px;
            font-size: 14px;
        }
        
        .status.success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .status.error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        .status.warning {
            background: #fff3cd;
            color: #856404;
            border: 1px solid #ffeaa7;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Windows 11 通知测试</h1>
        <p>点击下面的按钮来触发系统通知</p>
        
        <button class="notification-btn" onclick="requestPermission()">请求通知权限</button>
        <button class="notification-btn" onclick="showSimpleNotification()">简单通知</button>
        <button class="notification-btn" onclick="showRichNotification()">丰富通知</button>
        
        <div id="status" class="status" style="display: none;"></div>
    </div>

    <script>
        // 检查浏览器是否支持通知
        function checkNotificationSupport() {
            if (!('Notification' in window)) {
                showStatus('此浏览器不支持桌面通知', 'error');
                return false;
            }
            return true;
        }

        // 显示状态信息
        function showStatus(message, type = 'success') {
            const statusDiv = document.getElementById('status');
            statusDiv.textContent = message;
            statusDiv.className = `status ${type}`;
            statusDiv.style.display = 'block';
            
            // 3秒后隐藏状态信息
            setTimeout(() => {
                statusDiv.style.display = 'none';
            }, 3000);
        }

        // 请求通知权限
        async function requestPermission() {
            if (!checkNotificationSupport()) return;
            
            try {
                const permission = await Notification.requestPermission();
                
                switch (permission) {
                    case 'granted':
                        showStatus('通知权限已授予！现在可以发送通知了。', 'success');
                        break;
                    case 'denied':
                        showStatus('通知权限被拒绝。请在浏览器设置中手动启用。', 'error');
                        break;
                    case 'default':
                        showStatus('通知权限请求被忽略。', 'warning');
                        break;
                }
            } catch (error) {
                showStatus('请求权限时出错：' + error.message, 'error');
            }
        }

        // 显示简单通知
        function showSimpleNotification() {
            if (!checkNotificationSupport()) return;
            
            if (Notification.permission === 'granted') {
                const notification = new Notification('Hello from Web!', {
                    body: '这是一个来自网页的简单通知消息。',
                    icon: ''
                });
                
                // 通知点击事件
                notification.onclick = function() {
                    window.focus();
                    notification.close();
                    showStatus('通知被点击了！', 'success');
                };
                
                // 3秒后自动关闭
                setTimeout(() => {
                    notification.close();
                }, 3000);
                
                showStatus('简单通知已发送！', 'success');
            } else {
                showStatus('请先授予通知权限', 'warning');
            }
        }

        // 显示丰富通知
        function showRichNotification() {
            if (!checkNotificationSupport()) return;
            
            if (Notification.permission === 'granted') {
                const notification = new Notification('🎉 重要提醒', {
                    body: '您有一条新消息！\n点击查看详情。',
                    icon: '',
                    badge: '',
                    tag: 'rich-notification',
                    requireInteraction: true,
                    silent: false,
                    timestamp: Date.now(),
                    data: {
                        url: window.location.href,
                        action: 'view_details'
                    }
                });
                
                notification.onclick = function() {
                    window.focus();
                    notification.close();
                    showStatus('丰富通知被点击！数据：' + JSON.stringify(notification.data), 'success');
                };
                
                showStatus('丰富通知已发送！', 'success');
            } else {
                showStatus('请先授予通知权限', 'warning');
            }
        }

        // 页面加载时检查当前权限状态
        window.addEventListener('load', function() {
            if (checkNotificationSupport()) {
                switch (Notification.permission) {
                    case 'granted':
                        showStatus('通知权限已授予，可以发送通知', 'success');
                        break;
                    case 'denied':
                        showStatus('通知权限被拒绝，请在浏览器设置中启用', 'error');
                        break;
                    case 'default':
                        showStatus('请点击"请求通知权限"按钮来启用通知', 'warning');
                        break;
                }
            }
        });
    </script>
</body>
</html>